import { Resource } from "@/mini3d";
import { FileLoader } from "three";
import side from "@/assets/texture/side.png";
import ocean from "@/assets/texture/ocean-blue-bg.png";
import rotationBorder1 from "@/assets/texture/rotationBorder1.png";
import rotationBorder2 from "@/assets/texture/rotationBorder2.png";
import chinaBlurLine from "@/assets/texture/chinaBlurLine.png";
import guangquan1 from "@/assets/texture/guangquan01.png";
import guangquan2 from "@/assets/texture/guangquan02.png";
import huiguang from "@/assets/texture/huiguang.png";
import flyLine from "@/assets/texture/flyLine2.png";
import pathLine from "@/assets/texture/pathLine2.png";
import arrow from "@/assets/texture/arrow.png";
import point from "@/assets/texture/point1.png";
import flyLineFocus from "@/assets/texture/guangquan01.png";
export class Assets {
  constructor(onLoadCallback = null) {
    this.onLoadCallback = onLoadCallback;
    this.init();
  }
  init() {
    this.instance = new Resource();
    // 添加Fileloader
    this.instance.addLoader(FileLoader, "FileLoader");
    // 资源加载进度
    this.instance.on("onProgress", (path, itemsLoaded, itemsTotal) => {
      let progress = (itemsLoaded / itemsTotal) * 100;
      let bfb = progress.toFixed(2) + "%!";
    });
    // 资源加载完成事件
    this.instance.on("onLoad", () => {
      this.onLoadCallback && this.onLoadCallback();
    });
    // 资源加载
    let base_url = "/";
    // let base_url = import.meta.env.BASE_URL;
    let assets = [
      { type: "Texture", name: "huiguang", path: huiguang },
      { type: "Texture", name: "rotationBorder1", path: rotationBorder1 },
      { type: "Texture", name: "rotationBorder2", path: rotationBorder2 },
      { type: "Texture", name: "guangquan1", path: guangquan1 },
      { type: "Texture", name: "guangquan2", path: guangquan2 },
      { type: "Texture", name: "chinaBlurLine", path: chinaBlurLine },
      { type: "Texture", name: "ocean", path: ocean },
      { type: "Texture", name: "side", path: side },
      { type: "Texture", name: "flyLine", path: flyLine },
      { type: "Texture", name: "flyLineFocus", path: flyLineFocus },
      { type: "Texture", name: "pathLine", path: pathLine },
      { type: "Texture", name: "arrow", path: arrow },
      { type: "Texture", name: "point", path: point },
      {
        type: "File",
        name: "zhejiang",
        path: base_url + "json/浙江省.json",
      },
      {
        type: "File",
        name: "china",
        path: base_url + "json/中华人民共和国.json",
      },
    ];
    // 资源加载
    this.instance.loadAll(assets);
  }
}
